<?php
// +----------------------------------------------------------------------
// | 2LILU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.2lilu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------

namespace Admin\Controller;
use Think\Controller;

class AdminController extends Controller {
    
    //put your code here
    public function _initialize() {
        //layout(FALSE);
        $manager_id = session('manager_id');
        if (empty($manager_id)) {
            $this->redirect('Login/index');
        }
        
        $ob = M("config");
        $config = $ob->field('name,data')->select();
        foreach ($config as $key => $value) {
            C($value['name'], $value['data']);
        }
        // 用户权限检查
        //var_dump(explode(',', C('NOT_AUTH_ACTION')));
//        $notAuth = in_array(MODULE_NAME, explode(',', C('NOT_AUTH_MODEL'))) || in_array(ACTION_NAME, explode(',', C('NOT_AUTH_ACTION')));
//        if (C('USER_AUTH_ON') && !$notAuth) {
//            \Org\Util\Rbac::AccessDecision() || $this->error('没有权限操作');
//        }
    }

    /**
     * 功能：UpYun通过Ajax上传图片
     * @param 
     * @return 返回图片的地址
     */
    public function ueditor() {
        $upyun = new \Libs\UpYun();
        $file = $_FILES['upfile'];
        $url = $upyun->upload($file);
        if($url){
            $result = ['state'=>'SUCCESS','url'=>$url,'title'=>$file['name']];
        }  else {
            $result = ['state'=>'图片上传失败！'];
        }
        //$this->ajaxReturn($arr, 'JSON');
        echo json_encode($result);
    }
    
    
    public function getGoodsList(){
        if(IS_AJAX){
            $key = I('keys');
            $cat_id = I('cat_id');
            $cla_id = I('cla_id');
            if(!empty($key)){
                $map['goods_title'] = array('like','%'.$key.'%');
            }
            
            if(!empty($cat_id) && $cat_id != 0){
                $map['cat_id'] = $cat_id;
            }
            
            $list = M('goods')->field('goods_id,goods_title,goods_thumb')->where($map)->select();
            foreach ($list as $key => $value) {
                $html .='<li pic_id="'.$value['goods_id'].'"><a class="del" title="删除">X</a>';
                $html .='<div class="focus-thumb"><img title="'.$value['goods_title'].'" src="'.$value['goods_thumb'].'"></div>';
                $html .='<p><a href="'.HOME_URL."/Goods/".$value['goods_id'].'" target="_blank">'.$value['goods_title'].'</a></p><input type="hidden" name="'.$cla_id.'[]" value="'.$value['goods_id'].'" /></li>';
            }
            $this->ajaxReturn($html);
        }
    }
    
    
}
